using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Visibility class.
	/// </summary>
	[Serializable]
	public partial class VisibilityCollection : ActiveList<Visibility, VisibilityCollection> 
	{	   
		public VisibilityCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Visibility table.
	/// </summary>
	[Serializable]
	public partial class Visibility : ActiveRecord<Visibility>
	{
		#region .ctors and Default Settings
		
		public Visibility()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Visibility(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Visibility(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Visibility(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Visibility", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarVisibilityID = new TableSchema.TableColumn(schema);
				colvarVisibilityID.ColumnName = "VisibilityID";
				colvarVisibilityID.DataType = DbType.Int32;
				colvarVisibilityID.MaxLength = 0;
				colvarVisibilityID.AutoIncrement = true;
				colvarVisibilityID.IsNullable = false;
				colvarVisibilityID.IsPrimaryKey = false;
				colvarVisibilityID.IsForeignKey = false;
				colvarVisibilityID.IsReadOnly = false;
				colvarVisibilityID.DefaultSetting = @"";
				colvarVisibilityID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarVisibilityID);
				
				TableSchema.TableColumn colvarVisibilityCode = new TableSchema.TableColumn(schema);
				colvarVisibilityCode.ColumnName = "VisibilityCode";
				colvarVisibilityCode.DataType = DbType.Int32;
				colvarVisibilityCode.MaxLength = 0;
				colvarVisibilityCode.AutoIncrement = false;
				colvarVisibilityCode.IsNullable = false;
				colvarVisibilityCode.IsPrimaryKey = true;
				colvarVisibilityCode.IsForeignKey = true;
				colvarVisibilityCode.IsReadOnly = false;
				colvarVisibilityCode.DefaultSetting = @"";
				
					colvarVisibilityCode.ForeignKeyTableName = "Visibility";
				schema.Columns.Add(colvarVisibilityCode);
				
				TableSchema.TableColumn colvarVisibilityName = new TableSchema.TableColumn(schema);
				colvarVisibilityName.ColumnName = "VisibilityName";
				colvarVisibilityName.DataType = DbType.String;
				colvarVisibilityName.MaxLength = 100;
				colvarVisibilityName.AutoIncrement = false;
				colvarVisibilityName.IsNullable = true;
				colvarVisibilityName.IsPrimaryKey = false;
				colvarVisibilityName.IsForeignKey = false;
				colvarVisibilityName.IsReadOnly = false;
				colvarVisibilityName.DefaultSetting = @"";
				colvarVisibilityName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarVisibilityName);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = true;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				
						colvarDateAdded.DefaultSetting = @"(getdate())";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = true;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				
						colvarDateModified.DefaultSetting = @"(getdate())";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("Visibility",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("VisibilityID")]
		public int VisibilityID 
		{
			get { return GetColumnValue<int>("VisibilityID"); }

			set { SetColumnValue("VisibilityID", value); }

		}

		  
		[XmlAttribute("VisibilityCode")]
		public int VisibilityCode 
		{
			get { return GetColumnValue<int>("VisibilityCode"); }

			set { SetColumnValue("VisibilityCode", value); }

		}

		  
		[XmlAttribute("VisibilityName")]
		public string VisibilityName 
		{
			get { return GetColumnValue<string>("VisibilityName"); }

			set { SetColumnValue("VisibilityName", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime? DateAdded 
		{
			get { return GetColumnValue<DateTime?>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime? DateModified 
		{
			get { return GetColumnValue<DateTime?>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.OutdoorLogCollection OutdoorLogRecords()
		{
			return new Adex.OutdoorLogCollection().Where(OutdoorLog.Columns.VisibilityCode, VisibilityCode).Load();
		}

		public Adex.VisibilityCollection ChildVisibilityRecords()
		{
			return new Adex.VisibilityCollection().Where(Visibility.Columns.VisibilityCode, VisibilityCode).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Visibility ActiveRecord object related to this Visibility
		/// 
		/// </summary>
		public Adex.Visibility ParentVisibility
		{
			get { return Adex.Visibility.FetchByID(this.VisibilityCode); }

			set { SetColumnValue("VisibilityCode", value.VisibilityCode); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varVisibilityCode,string varVisibilityName,DateTime? varDateAdded,DateTime? varDateModified)
		{
			Visibility item = new Visibility();
			
			item.VisibilityCode = varVisibilityCode;
			
			item.VisibilityName = varVisibilityName;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varVisibilityID,int varVisibilityCode,string varVisibilityName,DateTime? varDateAdded,DateTime? varDateModified)
		{
			Visibility item = new Visibility();
			
				item.VisibilityID = varVisibilityID;
				
				item.VisibilityCode = varVisibilityCode;
				
				item.VisibilityName = varVisibilityName;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string VisibilityID = @"VisibilityID";
			 public static string VisibilityCode = @"VisibilityCode";
			 public static string VisibilityName = @"VisibilityName";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

